import { createPinia } from "pinia";
import { createPersistedState } from 'pinia-plugin-persistedstate'
import useUserStore from "./modules/useUserStore";
import useImStore from "./modules/useImStore";
import useAppStore from "./modules/useAppStore";
import useVoiceCallStore from "./modules/useVoiceCallStore";

export {
	useUserStore,
	useImStore,
	useAppStore,
	useVoiceCallStore,
};
const pinia = createPinia();
pinia.use(customStorage()); // 使用pinia插件，将数据持久化到本地存储中。
function customStorage() {
	return createPersistedState({
		key: id => `lawyer-user-${id}`,
		storage: {
			getItem(key : string) {
				return uni.getStorageSync(key)
			},
			setItem(key : string, value : any) {
				uni.setStorageSync(key, value)
			}
		}
	})
}

export default pinia;